version: "3.8"


services:
  clickhouse-db:
    container_name: clickhouse-db
    image: clickhouse/clickhouse-server:23.4.2.11
    healthcheck:
      test: apt update -y && apt install curl -y && echo 'SELECT 1' | curl 'http://localhost:8123/' --data-binary @-
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped
    ports:
      - 8123:8123/tcp
    volumes:
      - ./volumes/clickhouse:/var/lib/clickhouse:z
    environment:
      CLICKHOUSE_PASSWORD: 
      CLICKHOUSE_USER: default

  clickhouse-migration-runner:
    image: clickhouse-migration-runner-local
    build:
      context: .
      dockerfile: docker/dockerfiles/dockerfile_clickhouse_migration_runner
    depends_on:
      clickhouse-db:
        condition: service_healthy
    environment:
      CLICKHOUSE_HOST: clickhouse-db
      CLICKHOUSE_PORT: 8123

  helicone-be-db:
    container_name: helicone-be-db
    image: postgres:15.4
    restart: unless-stopped
    ports:
      - 25432:5432/tcp
    environment:
      POSTGRES_USER: postgres
      POSTGRES_DB: helicone
      POSTGRES_PASSWORD: password
    healthcheck:
      test: pg_isready -U postgres
      interval: 5s
      timeout: 5s
      retries: 10

  helicone-be-db-migration-runner:
    container_name: helicone-be-db-migration-runner
    image: flyway/flyway
    depends_on:
      helicone-be-db:
        condition: service_healthy
    volumes:
      - ./valhalla/migrations:/flyway/sql:z
    environment:
      - FLYWAY_URL=jdbc:postgresql://helicone-be-db:5432/helicone
      - FLYWAY_USER=postgres
      - FLYWAY_PASSWORD=password
      - FLYWAY_SCHEMAS=public
      - FLYWAY_LOCATIONS=filesystem:/flyway/sql
    command: migrate

  jawn:
    image: jawn-local
    build: 
      context: ./valhalla/
      dockerfile: ./dockerfile
    command: yarn dev:jawn
    ports:
      - 8585:8585
    volumes: 
      - ./valhalla:/usr/src/app:cached
    environment:
      - AURORA_CREDS={"username":"postgres", "password":"password"}
      - AURORA_HOST=helicone-be-db
      - AURORA_PORT=5432
      - AURORA_DATABASE=helicone
      - ENV=development
      - PORT=8585

  web:
    image: web-local
    build:
      context: .
      dockerfile: ./web/dockerfile-local
    ports:
      - 3000:3000
    volumes:
      - ./web:/usr/src/app:cached

  worker-openai-proxy:
    image: worker-local
    build:
      context: .
      dockerfile: ./worker/dockerfile-local
    ports:
      - 8787:8787
    volumes:
      - ./worker:/usr/src/app:cached
    environment:
      - PORT=8787
      - WORKER_TYPE=OPENAI_PROXY

  worker-anthropic-proxy:
    image: worker-local
    build:
      context: .
      dockerfile: ./worker/dockerfile-local
    ports:
      - 8789:8789
    volumes:
      - ./worker:/usr/src/app:cached
    environment:
      - PORT=8789
      - WORKER_TYPE=ANTHROPIC_PROXY

  worker-helicone-api:
    image: worker-local
    build:
      context: .
      dockerfile: ./worker/dockerfile-local
    ports:
      - 8788:8788
    volumes:
      - ./worker:/usr/src/app:cached
    environment:
      - PORT=8788
      - WORKER_TYPE=HELICONE_API
